home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FLOAT / FPSQRT.ASM < prev    next >
Assembly Source File  |  1989-01-24  |  3KB  |  88 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAIMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Last Update 5 Oct 87   Version 2.0
  6. ;
  7. fpsqrt  ident   2,0
  8. ;
  9. ; MOTOROLA DSP56000/1 FPLIB - VERSION 2
  10. ;
  11. ; FPSQRT - FLOATING POINT SQUARE ROOT SUBROUTINE
  12. ;
  13. ; Entry points: fsqrt_a R = square root(A)
  14. ;               fsqrt_x R = square root(X)
  15. ;
  16. ;       m = 24 bit mantissa (two's complement, normalized fraction)
  17. ;
  18. ;       e = 14 bit exponent (unsigned integer, biased by +8191)
  19. ;
  20. ; Input variables:
  21. ;
  22. ;   X   x1 = mx  (normalized)
  23. ;       x0 = ex
  24. ;
  25. ;   A   a2 = sign extension of ma
  26. ;       a1 = ma  (normalized)
  27. ;       a0 = zero
  28. ;
  29. ;       b2 = sign extension of ea (always zero)
  30. ;       b1 = ea
  31. ;       b0 = zero
  32. ;
  33. ; Output variables:
  34. ;
  35. ;   R   a2 = sign extension of mr
  36. ;       a1 = mr  (normalized)
  37. ;       a0 = zero
  38. ;
  39. ;       b2 = sign extension of er (always zero)
  40. ;       b1 = er
  41. ;       b0 = zero
  42. ;
  43. ; Error conditions:     Set CCR L=1 if input value is negative.  Result
  44. ;                       is set to floating point zero.  The CCR L bit
  45. ;                       remains set until cleared by the user.
  46. ;
  47. ; Assumes n0, m0, shift constant table and scaling modes
  48. ; initialized by previous call to the subroutine "fpinit".
  49. ;
  50. ; Alters Data ALU Registers
  51. ;       a2      a1      a0      a
  52. ;       b2      b1      b0      b
  53. ;       x1      x0      y1      y0
  54. ;
  55. ; Alters Address Registers
  56. ;       r0
  57. ;
  58. ; Alters Program Control Registers
  59. ;       pc      sr
  60. ;       la      lc
  61. ;       ssh     ssl     sp
  62. ;
  63. ; Uses 2 locations on System Stack
  64. ;
  65. ;
  66. fsqrt_x tfr     x0,b    x1,a            ;get mx,ex
  67. fsqrt_a tst     a       fp_space:fp_ebias,x0    ;check for negative input
  68.         jmi     under                   ;jump if negative, set L bit
  69.         jeq     done                    ;jump if zero
  70.         sub     x0,b                    ;remove ebias from ea
  71.         lsr     b       #<$40,y0        ;er' = ea / 2, get first guess
  72.         jcc     _sqrt1                  ;jump if er' even
  73.         asr     a       fp_space:fp_m1,x1       ;divide ma by 2, get -1
  74.         sub     x1,b                    ;increment er' by 1
  75. _sqrt1  add     x0,b    y0,x0           ;add ebias to er', save first temp
  76.         clr     b       b,r0            ;clear root, save er'
  77.         do      #23,_sqrt2              ;square all 23 bits
  78.         mac     -x0,x0,a        a,x1    ;square temp, save ma
  79.         tge     x0,b                    ;update root if correct guess
  80.         move    y0,a                    ;get guess bit
  81.         asr     a                       ;try next bit
  82.         add     b,a     a,y0            ;form root guess, save guess bit
  83.         tfr     x1,a    a,x0            ;get ma, save temp
  84. _sqrt2
  85.         tfr     b,a     r0,b            ;get root mr, er
  86.         rts
  87.